package com.daniel.design.pattern.singleton.demo5;

/**
 * @ClassName Singleton
 * @Description 懒汉式（同步代码块）双重检查锁
 * @Author Daniel
 * @Version V1.0.0
 */
public class Singleton {

    /**
     * 静态成员变量创建对象
     */
    private static Singleton instance;

    /**
     * 私有化构造函数
     */
    private Singleton() {
    }

    /**
     * 对外提供静态方法获取静态变量
     *
     * @return
     */
    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }
}
